<?php
function init($object) {
    $object->UserLevel = $object->_session('UserLevel');
    $object->UserName = $object->_session('UserName');
    $object->UserId = $object->_session('UserId');
    if (!isset($object->UserLevel)) {
        $object->MenuList = array('Home', 'Course', 'Problem', 'Source', 'Message', 'Login');
    }
    else if ($object->UserLevel == 1){
        $object->MenuList = array('Home', 'Course', 'Problem', 'Message', 'Source', 'Logout');
    }
    else if ($object->UserLevel == 2){
        $object->MenuList = array('Home', 'Course', 'Problem', 'AddProblem', 'Message', 'Source', 'Logout');
    }
    else if ($object->UserLevel == 3){
        $object->MenuList = array('Home', 'AddUser', 'UserManage', 'AddCourse', 'Course', 'Problem', 'Message', 'Source', 'Logout');
    }
    $object->UrlList        = array('Index'         => '/',
                                    'Home'          => '/index.php/Index/home',
                                    'Course'        => '/index.php/Course',
                                    'Problem'       => '/index.php/Problem',
                                    'AddProblem'    => '/index.php/Problem/addproblem',
                                    'Message'       => '/index.php/Message',
                                    //'Mine'          => '/index.php/Mine',
                                    'Login'         => '/index.php/Member/login',
                                    'Logout'        => '/index.php/Member/logout',
                                    'Source'        => '/index.php/Source',
                                    'AddUser'       => '/index.php/Member/adduser',
                                    'AddCourse'     => '/index.php/Course/addcourse',
                                    'UserManage'    => '/index.php/Member/usermanage'
                                    );
    $object->SystemName     = 'HomeWork';
}
function translatetime($tmp) {
    if (isset($tmp) && $tmp != NULL)
    return substr($tmp, 0, 4)."-".substr($tmp, 4, 2)."-".substr($tmp, 6, 2)." ".substr($tmp, 8, 2).":".substr($tmp, 10, 2).":".substr($tmp, 12, 2);
}
function gohistory() {
    echo "<script>window.location.href='javascript:history.go(-1)';</script>";
}
//下载文件
function download_file($file){
    if(is_file($file)){
        $length = filesize($file);
        $type = mime_content_type($file);
        $showname =  ltrim(strrchr($file,'/'),'/');
        header("Content-Description: File Transfer");
        header('Content-type: ' . $type);
        header('Content-Length:' . $length);
         if (preg_match('/MSIE/', $_SERVER['HTTP_USER_AGENT'])) { //for IE
             header('Content-Disposition: attachment; filename="' . rawurlencode($showname) . '"');
         } else {
             header('Content-Disposition: attachment; filename="' . $showname . '"');
         }
         readfile($file);
         exit;
     } else {
         exit('文件已被删除！');
     }
 }
// "/index.php/Message/notedetail"
?>
